import responseConverter from 'emberworkspace/utils/response-converter';
import { module, test } from 'qunit';

module('Unit | Utility | response converter');

var users = {
      "_links": {
        "self": {
          "href": "http://localhost/api/v1/people{?page,size,sort,projection}",
          "templated": true
        },
        "search": {
          "href": "http://localhost/api/v1/people/search"
        }
      },
      "_embedded": {
        "people": [ {
          "id": 4,
          "displayName": "96ad56@m3958.com",
          "name": "中文名",
          "enabled": "true",
          "roles": [{
            "name": "ROLE_USER",
            "id": 1
          }, {
            "name": "ROLE_USER_MANAGER",
            "id": 4
          }],
          "level": 1,
          "createdAt": "2015-09-01T14:42:00.273+0000",
          "lastScheduleExec": null,
          "avatar": "",
          "gender": "FEMAIL",
          "email": "96ad5c25402c4e57854510da6e1e6146@m3958.com",
          "ucOpenId": "96ad5c25402c4e57854510da6e1e6146",
          "_embedded": {
            "roles": [{
              "name": "ROLE_USER",
              "id": 1,
              "_links": {
                "self": {
                  "href": "http://localhost/api/v1/roles/1{?projection}",
                  "templated": true
                }
              }
            }, {
              "name": "ROLE_USER_MANAGER",
              "id": 4,
              "_links": {
                "self": {
                  "href": "http://localhost/api/v1/roles/4{?projection}",
                  "templated": true
                }
              }
            }]
          },
          "_links": {
            "self": {
              "href": "http://localhost/api/v1/people/4{?projection}",
              "templated": true
            },
            "roles": {
              "href": "http://localhost/api/v1/people/4/roles"
            },
            "taskLists": {
              "href": "http://localhost/api/v1/people/4/taskLists"
            },
            "keypairs": {
              "href": "http://localhost/api/v1/people/4/keypairs"
            }
          }
        }]
      },
      "page": {
        "size": 2,
        "totalElements": 3,
        "totalPages": 2,
        "number": 0
      }
    };

var mockStore = {
  modelFor: function() {
    return true;
  }
};

// Replace this with your real tests.
test('list response should work', function(assert) {
  let result = responseConverter(mockStore, {modelName: 'person'}, users, -1, 'normalizeQueryResponse');
  assert.equal(1, result.data.length);

  let one = result.data[0];
  assert.equal("4", one.id);
  assert.notOk(one._links);
  assert.notOk(one._embedded);
  assert.notOk(one.roles);
  assert.ok(result);
});

test('single record response should work', function(assert) {
  let result = responseConverter(mockStore, {modelName: 'person'}, users._embedded.people[0], -1, 'normalizeQueryRecordResponse');
  console.log(result);
  let one = result.data;
  assert.equal("4", one.id);
  assert.notOk(one._links);
  assert.notOk(one._embedded);
  assert.notOk(one.roles);
  assert.ok(result);
});
